package net.maku.propagate.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.propagate.convert.PropagateWorkerConvert;
import net.maku.propagate.entity.PropagateWorkerEntity;
import net.maku.propagate.query.PropagateWorkerQuery;
import net.maku.propagate.vo.PropagateWorkerVO;
import net.maku.propagate.dao.PropagateWorkerDao;
import net.maku.propagate.service.PropagateWorkerService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 劳模风采
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-16
 */
@Service
@AllArgsConstructor
public class PropagateWorkerServiceImpl extends BaseServiceImpl<PropagateWorkerDao, PropagateWorkerEntity> implements PropagateWorkerService {

    @Override
    public PageResult<PropagateWorkerVO> page(PropagateWorkerQuery query) {
        IPage<PropagateWorkerEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(PropagateWorkerConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<PropagateWorkerEntity> getWrapper(PropagateWorkerQuery query){
        LambdaQueryWrapper<PropagateWorkerEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(PropagateWorkerVO vo) {
        PropagateWorkerEntity entity = PropagateWorkerConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(PropagateWorkerVO vo) {
        PropagateWorkerEntity entity = PropagateWorkerConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}